package 小练习;

public class Main {
    public static void main(String[] args) {
        ListCode list = new ListCode(1);
        list.addData(2);
        list.addData(3);
        list.print();
    }
}

class ListCode{
    ListCode next;
    int ListData;

    ListCode(int data){
        ListData = data;
    }

    void addData(int data){
        ListCode List = new ListCode(data);
        if(this.next == null){
            this.next = List;
        }else{
            this.next.addData(data);  //注意这里不能写成 this.next这相当于重复调用，有异常
        }
    }

    void print(){
        System.out.println(this.ListData);
        if(this.next != null){
            this.next.print();
        }
    }
}
